/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.server.modules.sys.web.juhe.usedcar;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.server.common.config.Global;
import com.server.common.persistence.Page;
import com.server.common.web.BaseController;
import com.server.common.utils.StringUtils;
import com.server.modules.sys.entity.juhe.usedcar.JuheUsedcarModelYear;
import com.server.modules.sys.service.juhe.usedcar.JuheUsedcarModelYearService;

/**
 * 聚合二手车接口车辆型号年份数据Controller
 * @author 丁光彪
 * @version 2017-01-06
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/juhe.usedcar/juheUsedcarModelYear")
public class JuheUsedcarModelYearController extends BaseController {

	@Autowired
	private JuheUsedcarModelYearService juheUsedcarModelYearService;
	
	@ModelAttribute
	public JuheUsedcarModelYear get(@RequestParam(required=false) String id) {
		JuheUsedcarModelYear entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = juheUsedcarModelYearService.get(id);
		}
		if (entity == null){
			entity = new JuheUsedcarModelYear();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:juhe.usedcar:juheUsedcarModelYear:view")
	@RequestMapping(value = {"list", ""})
	public String list(JuheUsedcarModelYear juheUsedcarModelYear, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<JuheUsedcarModelYear> page = juheUsedcarModelYearService.findPage(new Page<JuheUsedcarModelYear>(request, response), juheUsedcarModelYear); 
		model.addAttribute("page", page);
		model.addAttribute("juheUsedcarModelYear", juheUsedcarModelYear);
		return "modules/sys/juhe.usedcar/juheUsedcarModelYearList";
	}

	@RequiresPermissions("sys:juhe.usedcar:juheUsedcarModelYear:view")
	@RequestMapping(value = "form")
	public String form(JuheUsedcarModelYear juheUsedcarModelYear, Model model) {
		model.addAttribute("juheUsedcarModelYear", juheUsedcarModelYear);
		return "modules/sys/juhe.usedcar/juheUsedcarModelYearForm";
	}

	@RequiresPermissions("sys:juhe.usedcar:juheUsedcarModelYear:edit")
	@RequestMapping(value = "save")
	public String save(JuheUsedcarModelYear juheUsedcarModelYear, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, juheUsedcarModelYear)){
			return form(juheUsedcarModelYear, model);
		}
		juheUsedcarModelYearService.save(juheUsedcarModelYear);
		addMessage(redirectAttributes, "保存聚合二手车接口车辆型号年份数据成功");
		return "redirect:"+Global.getAdminPath()+"/sys/juhe.usedcar/juheUsedcarModelYear/?repage";
	}
	
	@RequiresPermissions("sys:juhe.usedcar:juheUsedcarModelYear:edit")
	@RequestMapping(value = "delete")
	public String delete(JuheUsedcarModelYear juheUsedcarModelYear, RedirectAttributes redirectAttributes) {
		juheUsedcarModelYearService.delete(juheUsedcarModelYear);
		addMessage(redirectAttributes, "删除聚合二手车接口车辆型号年份数据成功");
		return "redirect:"+Global.getAdminPath()+"/sys/juhe.usedcar/juheUsedcarModelYear/?repage";
	}

}